package com.example.administrator.myapplication;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

public class TestActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test);

        final List<Teacher> data=new ArrayList<Teacher>();
        Teacher t1=new Teacher("002","john");
        Teacher t2=new Teacher("003","tom");
        data.add(t1);data.add(t2);

        AutoCompleteTextView teachersTv=(AutoCompleteTextView)findViewById(R.id.tv_name);
        ArrayAdapter<Teacher> adapter=new ArrayAdapter<Teacher>(this,android.R.layout.simple_list_item_1,data);
        teachersTv.setAdapter(adapter);

        teachersTv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Teacher t=data.get(position);
                Toast.makeText(TestActivity.this,t.getId(),Toast.LENGTH_SHORT).show();
            }
        });
    }
}
